using System.Globalization;
using imitateMacQQ.WebApi.Configures;

namespace imitateMacQQ.WebApi.Repository.EFCore.Model.utils;

public class UtilsTime
{
    private readonly INLogHelper _logHelper;

    public UtilsTime(INLogHelper logHelper)
    {
        _logHelper = logHelper;
    }

    public async void DelEndTimePhone()
    {
        //清理过期信息
        try
        {
            await using var db = new DataDbContext();
            _logHelper.Log(DateTime.Now.ToString(CultureInfo.InvariantCulture)
                           + ":CLEAR TIME OUT DATA!");
            var info = db.PhoneCodes.Where(e => e.EndTime < DateTime.Now).ToList();
            if (info.Count is 0)
                return;
            db.PhoneCodes.RemoveRange(info);
            await db.SaveChangesAsync();
        }
        catch (Exception ex)
        {
            _logHelper.LogError(ex);
        }
    }
}